 /*
 * @name: 远程工作 查看提交(废弃)
 * @Author: along
 * @Date: 2019-06-16
 * @Last Modified by: along
 * @Last Modified time: 2020-06-16
 */
<template>
    <div class="container workTaskSubmit">
        <!-- header -->
        <div class="header-nav">
            <div class="header-left">
                <div class="header-new-box text">
                    任务名称: {{ formInfo.title }}
                </div>
                <div class="header-new-box text">
                    浏览量: {{ formInfo.view_count }}
                </div>
                <div class="header-new-box text">
                    提交量: {{ formInfo.submit_count }}
                </div>
                <div class="header-new-box">
                    <p class="header-new-box-title">学校名称:</p>
                    <el-select
                        v-model="head.school"
                        clearable
                        filterable
                        placeholder="请选择"
                        size="small"
                        @change="getTableData(1)"
                    >
                        <el-option
                            v-for="item in optionSchool"
                            :key="item.value"
                            :label="item.label"
                            :value="item.value"/>
                    </el-select>
                </div>
            </div>
            <div class="header-right">
                <div class="header-new-box">
                    <el-button
                        type="primary"
                        size="small"
                        @click="fnExport()"
                    >
                        导出
                    </el-button>
                </div>
            </div>
        </div>
        <!-- /header -->

        <!-- table -->
        <el-table
            :data="tableData"
            height="100%"
            style="width: 100%;"
            border
            ref="workTaskSubmit"
        >
            <el-table-column
                type="index"
                width="80"
                label="序号"
                align="center"
            />
            <el-table-column
                label="填写人"
                align="center"
                show-overflow-tooltip
                :formatter="emptyFormatter"
            >
                <template slot-scope="scope">
                    <div>
                        {{ scope.row.student_info.true_name }}/{{ scope.row.student_info.school }}
                    </div>
                </template>
            </el-table-column>
            <el-table-column
                label="填写时间"
                align="center"
                show-overflow-tooltip
                :formatter="emptyFormatter"
            >
                <template slot-scope="scope">
                    <div>
                        {{ scope.row.create_time * 1000 | dateFormatter('yyyy/MM/dd HH:mm') }}
                    </div>
                </template>
            </el-table-column>
            <el-table-column
                label="填写详情"
                align="center"
                show-overflow-tooltip
                :formatter="emptyFormatter"
            >
                <template slot-scope="scope">
                    <span
                        class="cursor-font"
                        @click="fnGoForm(scope.row)"
                        handlance
                    >查看</span>
                </template>
            </el-table-column>
            <el-table-column
                align="center"
                show-overflow-tooltip
                :formatter="emptyFormatter"
                v-for="(item,index) in formInfo.form_config"
                :key="index"
                :label="item.title"
            >
                <template slot-scope="scope">
                    <!-- text || textarea || radio -->
                    <div v-if="item.type == 1 || item.type == 6 || item.type == 2">
                        {{ scope.row.form_data_value[item.name] }}
                    </div>
                    <!-- checkbox -->
                    <div v-if="item.type == 3">
                        <p
                            v-for="(itm,idx) in scope.row.form_data_value[item.name]"
                            :key="idx"
                        >
                            {{ itm }}{{ (idx == 0 && scope.row.form_data_value[item.name].length == 0) || (idx == scope.row.form_data_value[item.name].length - 1) ? '' : ';' }}
                        </p>
                    </div>
                    <div v-else-if="item.type == 5 || item.type == 8">
                        <p
                            v-if="scope.row.form_data_value[item.name].length > 0"
                            class="cursor-font"
                            @click="fnShowPreview(scope.row.form_data_value[item.name])"
                        >
                            查看
                        </p>
                        <p v-else>--</p>
                    </div>
                    <div v-else-if="item.type == 7">
                        {{ scope.row.form_data_value[item.name] == "" ? '--' : scope.row.form_data_value[item.name] * 1000 | dateFormatter('yyyy/MM/dd HH:mm') }}
                    </div>
                    <!-- 增加视频类型 -->
                    <div v-else-if="item.type == 9">
                        <p
                            v-if="scope.row.form_data_value[item.name].length > 0"
                            class="cursor-font"
                            @click="fnShowVideo(scope.row.form_data_value[item.name])"
                        >
                            查看
                        </p>
                        <p v-else>--</p>
                    </div>
                </template>
            </el-table-column>
        </el-table>
        <!-- /table -->

        <!-- /统计数量 -->
        <div class="pagination-wrapper clearfix">
            <el-button
                size="small"
                type="default"
            >
                共{{ allSubmit }}条
            </el-button>
        </div>

        <!-- 图片预览 -->
        <img-preview ref="preview" />
    </div>
</template>

<script>
import imgPreview from '@/components/common/img-preview';
import { back } from '@/mixin/back';
export default {
    mixins: [back],
    components: {
        imgPreview
    },
    data () {
        return {
            allSubmit: 0,
            formInfo: {},
            head: {
                school: ''
            },
            optionSchool: [{
                value: '',
                label: '全部'
            }],
            page: {
                now_page: 1,
                total_count: 0,
                page_size: 0
            },
            tableData: [],
            authResult: {},
            task_no: ''
        };
    },
    filters: {},
    computed: {},
    watch: {},
    created () {
        let query = this.$route.query;

        if(query.task_no) {
            this.task_no = query.task_no;
        }
    },
    mounted () {
        this.$store.commit('SET_HEADER', [{ title: "APP后台"},{title: '工作'},{title: '远程任务'},{title: '查看提交'}]);
        this.authResult = this.$route.meta.authResult;
        this.getTableData();
        this.getSchoolList();
    },
    methods: {
        /**
         * 获取表格数据
         */
        getTableData (page) {
            this.$post('/student/taskonline_student_task%5Cget_submit_list', {
                task_no: this.task_no,
                user_school_id: this.head.school,
            }, resp => {
                if (resp.code == 1) {
                    this.formInfo = resp.data.task_info	;
                    this.tableData = resp.data.list;
                    this.allSubmit = this.formInfo.submit_count;
                }
            });
        },

        /**
         * 获取学校数据列表
         */
        getSchoolList () {
            this.$post('/student/custom_form_data%5Cget_user_school_list', {
                task_no: this.task_no,
            }, resp => {
                if (resp.code == 1) {
                    let list = [];

                    resp.data.list.map(item => {
                        list.push({
                            value: item.id,
                            label: item.name
                        });
                    });

                    this.optionSchool = this.optionSchool.concat(list);
                }
            });
        },

        /**
         * 导出数据
         */
        fnExport () {
            let base = this.$baseUrl;
            let ticket = localStorage.getItem('sessionTicket');
            let url = `${base}/student/custom_form_data%5Cexport_list?task_no=${this.task_no}&__ticket=${ticket}`;

            window.open(url);
        },

        /**
         * 预览表单
         */
        fnGoForm (row) {
            // this.$router.push({
            //     name: 'workTaskpreview',
            //     query: {
            //         id: row.id
            //     }
            // });
        },

        /**
         * 查看图片
         * @param   {String}    images      //单图预览
         * @param   {Array}     images      //多图预览
         */
        fnShowPreview(images) {
            if(images && Object.prototype.toString.call(images) == '[object String]') {
                this.$refs.preview.show([
                    images
                ]);
            } else if (images && Object.prototype.toString.call(images) == '[object Array]') {
                this.$refs.preview.show(images);
            } else {
                this.$message({
                    type: 'warning',
                    message: '图片类型错误'
                });
            }
        },

        /**
         * 查看视频
         */
        fnShowVideo (row) {
            // console.log(row, '1');
        },

        /**
         * 过滤函数
         */
        emptyFormatter(row, column, val) {
            if (!val) return '--';
            return val;
        }
    }
};
</script>

<style lang="less" scoped>
    .container {
        background-color: #fff;
        padding: 10px 15px 5px 15px;
        display: flex;
        flex-direction: column;
        position: relative;
        width: 100%;
        .header-nav {
            position: relative;
            display: flex;
            flex-wrap: wrap;
            align-items: center;
            justify-content: space-between;
            .header-left, .header-right {
                display: flex;
                align-items: center;
                flex-wrap: wrap;
            }
            .header-new-box {
                display: flex;
                margin-right: 15px;
                align-items: center;
                color: #606266;
                margin-bottom: 10px;
                white-space: nowrap;
                &-title {
                    margin-right: 2px;
                    white-space: nowrap;
                }
            }
        }
        /* 表单 */
        .scope-price {
            width: 50px;
            height: 50px;
        }
        /* 字体高亮 */
        .cursor-font {
            color: rgb(64, 158, 255);
            cursor: pointer;
        }
        /* 分页 */
        .pagination-wrapper {
            padding-top: 10px;
            padding-bottom: 10px;
            display: flex;
            flex-direction: row-reverse;
            color: #606266;
            .el-pagination {
                float: right;
                padding: 0;
                background-color: transparent;
            }
        }
    }
    /* 排序 */
    .sort-wrap {
        display: flex;
        align-items: center;
        justify-content: center;
        cursor: pointer;
        .sort-spliter {
            width: 1px;
            height: 12px;
            background: rgba(235, 235, 235, 1);
            margin: 0 10px;
            }
            .btn-sort {
            font-size: 14px;
            line-height: 1;
            color: #ccc;
            &:hover {
                color: #20a0ff;
            }
        }
    }
    .el-button-left {
        margin-left: 40px;
    }
    .el-button-right {
        margin-right: 10px;
    }
</style>
<style lang="less">
    .workTaskSubmit{
        .el-table__body-wrapper .el-table__body .el-table__row td {
            border-right: none;
        }
        .el-table__header-wrapper .el-table__header .has-gutter tr th {
            border-right: none;
        }
        .el-table .el-table_1_column_6  .cell {
            position: relative;
        }
        .el-range-editor--small .el-range-separator{
            padding: 0 1px !important;
        }
    }
</style>
